package com.dyz.leetcode;


import java.util.Arrays;
import java.util.Comparator;

public class MaxArea11 {
    public static void main(String[] args) {
        int[] height = new int[]{1,8,6,2,5,4,8,3,7};
        int sys = new MaxArea11().maxArea(height);
        System.out.println(sys);

    }
    public int maxArea(int[] height) {
        //使用双指针
        int l =0, r = height.length-1;
        int ans = 0;
        while (l<r){
            int area = Math.min(height[l], height[r])*(r-l);
            ans = Math.max(area, ans);
            if(height[l]<=height[r]){
                ++l;
            }else {
                --r;
            }
        }
        return ans;

    }
}
